package com.xiaoshuidi.cloud.module.member.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.member.api.message.dto.MemberMessageDTO;
import com.xiaoshuidi.cloud.module.member.controller.app.activities.vo.EnrollListVO;
import com.xiaoshuidi.cloud.module.member.controller.app.message.vo.MessageListVO;
import com.xiaoshuidi.cloud.module.member.controller.app.message.vo.MessagePageVO;
import com.xiaoshuidi.cloud.module.member.enums.MessageDestinationEnum;
import com.xiaoshuidi.cloud.module.member.mapper.message.MemberMessageMapper;
import com.xiaoshuidi.cloud.module.member.pojo.activities.MemberActivities;
import com.xiaoshuidi.cloud.module.member.pojo.message.MemberMessage;
import com.xiaoshuidi.cloud.module.member.pojo.topics.MemberTopics;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Repository
@RequiredArgsConstructor
@Slf4j
public class MemberMessageRepository extends ServiceImpl<MemberMessageMapper, MemberMessage> {
    private final MemberMessageMapper mapper;

    public MemberMessage create(MemberMessageDTO message) {
        MemberMessage memberMessage = new MemberMessage();
        BeanUtils.copyProperties(message, memberMessage);
        memberMessage.setUpdater(memberMessage.getCreator());
        mapper.insert(memberMessage);
        return memberMessage;
    }

    public PageResult<MessageListVO> getAppPage(MessagePageVO pageVO) {
        IPage<MessageListVO> result = mapper.getAppPage(new Page<MemberMessage>(pageVO.getPageNo(), pageVO.getPageSize()), pageVO);
        PageResult<MessageListVO> pageResult = PageResult.empty();
        pageResult.setList(result.getRecords());
        pageResult.setTotal(result.getTotal());
        return pageResult;

    }
}
